package com.css.zfzx.sjcj.modules.hddcActiveFault.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.sys.dict.repository.entity.DictItemEntity;
import com.css.bpm.platform.utils.*;
import com.css.zfzx.sjcj.common.spacedata.vo.SpaceDataParamsVo;
import com.css.zfzx.sjcj.common.utils.EasyPoiExcelUtil;
import com.css.zfzx.sjcj.common.utils.UpdateUtil;
//import com.css.zfzx.sjcj.config.filter.BeanRestTemplat;
import com.css.zfzx.sjcj.modules.hddcActiveFault.repository.HddcActivefaultNativeRepository;
import com.css.zfzx.sjcj.modules.hddcActiveFault.repository.HddcActivefaultRepository;
import com.css.zfzx.sjcj.modules.hddcActiveFault.repository.entity.HddcActivefaultEntity;
import com.css.zfzx.sjcj.modules.hddcActiveFault.service.HddcActivefaultService;
import com.css.zfzx.sjcj.modules.hddcActiveFault.viewobjects.HddcActivefaultQueryParams;
import com.css.zfzx.sjcj.modules.hddcActiveFault.viewobjects.HddcActivefaultVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @author zyb
 * @date 2020-11-30
 */
@Service
public class HddcActivefaultServiceImpl implements HddcActivefaultService {

	@Autowired
    private HddcActivefaultRepository hddcActivefaultRepository;
    @Autowired
    private HddcActivefaultNativeRepository hddcActivefaultNativeRepository;

/*
    @Autowired
    public static RestTemplate restTemplat;

    private static final String url="https://fxpc.mem.gov.cn/data_preparation/171dd1d5-bbb3-483a-a7f6-50d6d98cee1f/7a55d40f-b5e2-4888-a94e-f874693e8d0e/gposition?lon=116.399562&lat=39.911100&type=1&geokey=94E99EB4FEB9B48CD5348F7BCF5BB620";
*/


    @Override
    public JSONObject queryHddcActivefaults(HddcActivefaultQueryParams queryParams, int curPage, int pageSize,String sort,String order) {
        Page<HddcActivefaultEntity> hddcActivefaultPage = this.hddcActivefaultNativeRepository.queryHddcActivefaults(queryParams, curPage, pageSize, sort, order);
        JSONObject jsonObject = PlatformPageUtils.formatPageData(hddcActivefaultPage);
        return jsonObject;
    }


    @Override
    public HddcActivefaultEntity getHddcActivefault(String id) {
        HddcActivefaultEntity hddcActivefault = this.hddcActivefaultRepository.findById(id).orElse(null);
         return hddcActivefault;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcActivefaultEntity saveHddcActivefault(HddcActivefaultEntity hddcActivefault) {
        String uuid = UUIDGenerator.getUUID();
        hddcActivefault.setUuid(uuid);
        hddcActivefault.setCreateUser(PlatformSessionUtils.getUserId());
        hddcActivefault.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        hddcActivefault.setIsValid("1");
        hddcActivefault.setQualityinspectionStatus("0");
        hddcActivefault.setExtends10("1");
        this.hddcActivefaultRepository.save(hddcActivefault);
        return hddcActivefault;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Iterable<HddcActivefaultEntity> saveHddcActivefaultList(List<HddcActivefaultEntity> list) {
        for (HddcActivefaultEntity hddcActivefault : list) {
            String uuid = UUIDGenerator.getUUID();
            hddcActivefault.setUuid(uuid);
            hddcActivefault.setCreateUser(PlatformSessionUtils.getUserId());
            hddcActivefault.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            hddcActivefault.setIsValid("1");
            hddcActivefault.setQualityinspectionStatus("0");
            hddcActivefault.setExtends10("1");
        }
        Iterable<HddcActivefaultEntity> iterable = hddcActivefaultNativeRepository.batchSave(list);
        return iterable;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public HddcActivefaultEntity updateHddcActivefault(HddcActivefaultEntity hddcActivefault) {
        HddcActivefaultEntity entity = hddcActivefaultRepository.findById(hddcActivefault.getUuid()).get();
        UpdateUtil.copyNullProperties(entity,hddcActivefault);
        hddcActivefault.setUpdateUser(PlatformSessionUtils.getUserId());
        hddcActivefault.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        this.hddcActivefaultRepository.save(hddcActivefault);
        return hddcActivefault;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteHddcActivefaults(List<String> ids) {
        List<HddcActivefaultEntity> hddcActivefaultList = this.hddcActivefaultRepository.findAllById(ids);
        if(!PlatformObjectUtils.isEmpty(hddcActivefaultList) && hddcActivefaultList.size() > 0) {
            for(HddcActivefaultEntity hddcActivefault : hddcActivefaultList) {
//                this.hddcActivefaultRepository.delete(hddcActivefault);
                hddcActivefault.setIsValid("0");
                hddcActivefault.setUpdateUser(PlatformSessionUtils.getUserId());
                hddcActivefault.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                this.hddcActivefaultRepository.save(hddcActivefault);

            }
        }
    }

    @Override
    public List<DictItemEntity> getValidDictItemsByDictCode(String dictCode) {
        List<DictItemEntity> validDictItems = PlatformAPI.getDictAPI().getValidDictItemsByDictCode(dictCode);
        return validDictItems;
    }

    @Override
    public void exportFile(HddcActivefaultQueryParams queryParams, HttpServletResponse response) {
        List<HddcActivefaultEntity> yhDisasterEntities = hddcActivefaultNativeRepository.exportYhDisasters(queryParams);
        List<HddcActivefaultVO> list=new ArrayList<>();
        for (HddcActivefaultEntity entity:yhDisasterEntities) {
            HddcActivefaultVO yhDisasterVO=new HddcActivefaultVO();
            BeanUtils.copyProperties(entity,yhDisasterVO);
            list.add(yhDisasterVO);
        }
        EasyPoiExcelUtil.exportExcel(list, "活动断层-线", "活动断层-线", HddcActivefaultVO.class, "活动断层-线.xls", response);
    }

    @Override
    public String exportExcel(MultipartFile file, HttpServletResponse response) {
        try {
            // 返回的消息
            StringBuilder returnMsg = new StringBuilder();
            // 导入的参数信息
            ImportParams params = new ImportParams();
            // 设置简析的第一行
            params.setHeadRows(1);
            // 是否需要校验
            params.setNeedVerify(true);
            // 获取到Excel数据
            ExcelImportResult<HddcActivefaultVO> result = ExcelImportUtil.importExcelMore(file.getInputStream(), HddcActivefaultVO.class, params);
            List<HddcActivefaultVO> list = result.getList();
            // Excel条数据
            int firstList = list.size();
            StringBuilder sb = new StringBuilder();
            //保存
            saveDisasterList(list, sb);
            returnMsg.append("成功导入" + (result.getList().size() ));
            returnMsg.append(sb);
            if (result.isVerifyFail()) {
                // 校验返回失败行信息
                Iterator<HddcActivefaultVO> iterator = result.getFailList().iterator();
                while (iterator.hasNext()) {
                    HddcActivefaultVO yhDisasterVO = iterator.next();
                    String error = "";
                    returnMsg.append("第" + yhDisasterVO.getRowNum() + "行" + yhDisasterVO.getErrorMsg() + "<br/>");
                    returnMsg.append(error);
                }
            }
            return returnMsg.toString();
        } catch (Exception e) {

            return "导入失败，请检查数据正确性";
        }
    }
    public void saveDisasterList( List<HddcActivefaultVO> list, StringBuilder message) {
        for (int i = 0; i < list.size(); i++) {
            HddcActivefaultEntity yhDisasterEntity = new HddcActivefaultEntity();
            HddcActivefaultVO yhDisasterVO = list.get(i);
            // 将VO数据映射拷贝到库表中
            BeanUtils.copyProperties(yhDisasterVO, yhDisasterEntity);
            saveHddcActivefault(yhDisasterEntity);
        }
    }


    /**
     * 逻辑删除-根据项目id删除数据
     * @param projectIds
     */
    @Override
    public void deleteByProjectId(List<String> projectIds) {
        List<HddcActivefaultEntity> hddcA1InvrgnhasmaterialtableList = this.hddcActivefaultRepository.queryByProjectId(projectIds);
        if(!PlatformObjectUtils.isEmpty(hddcA1InvrgnhasmaterialtableList) && hddcA1InvrgnhasmaterialtableList.size() > 0) {
            for(HddcActivefaultEntity hddcA1Invrgnhasmaterialtable : hddcA1InvrgnhasmaterialtableList) {
                hddcA1Invrgnhasmaterialtable.setUpdateUser(PlatformSessionUtils.getUserId());
                hddcA1Invrgnhasmaterialtable.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                hddcA1Invrgnhasmaterialtable.setIsValid("0");
                this.hddcActivefaultRepository.save(hddcA1Invrgnhasmaterialtable);
            }
        }
    }

    /**
     * 逻辑删除-根据任务id删除数据
     * @param taskId
     */
    @Override
    public void deleteByTaskId(List<String> taskId) {
        List<HddcActivefaultEntity> hddcA1InvrgnhasmaterialtableList = this.hddcActivefaultRepository.queryByTaskId(taskId);
        if(!PlatformObjectUtils.isEmpty(hddcA1InvrgnhasmaterialtableList) && hddcA1InvrgnhasmaterialtableList.size() > 0) {
            for(HddcActivefaultEntity hddcA1Invrgnhasmaterialtable : hddcA1InvrgnhasmaterialtableList) {
                hddcA1Invrgnhasmaterialtable.setUpdateUser(PlatformSessionUtils.getUserId());
                hddcA1Invrgnhasmaterialtable.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                hddcA1Invrgnhasmaterialtable.setIsValid("0");
                this.hddcActivefaultRepository.save(hddcA1Invrgnhasmaterialtable);
            }
        }

    }

    @Override
    public List<HddcActivefaultEntity> findAll() {
        List<HddcActivefaultEntity> list=this.hddcActivefaultRepository.findAll();
        return list;
    }

    @Override
    @Transactional
    public void deleteFileData(SpaceDataParamsVo paramsVo) {
        String provinceName=paramsVo.getProvinceName();
        String cityName=paramsVo.getCityName();
        String areaName=paramsVo.getAreaName();
        String savefilename=paramsVo.getSavefilename();
        String uuser = PlatformSessionUtils.getUserId();
        Date deletedate=PlatformDateUtils.getCurrentTimestamp();
        hddcActivefaultRepository.deleteFileData(provinceName,cityName,areaName,savefilename,uuser,deletedate);
    }

    @Override
    public String judegeParams(String[] datas) {
        String str = "";
        Set<String> set = new HashSet<String>(Arrays.asList(datas));
        if(!set.contains("ID")){
            str+="ID,";
        }
        if(!set.contains("Scale")){
            str+="Scale,";
        }
        if(!set.contains("FractureZoneName")){
            str+="FractureZoneName,";
        }
        if(!set.contains("Name")){
            str+="Name,";
        }
        if(!set.contains("FaultSegmentName")){
            str+="FaultSegmentName,";
        }
        if(!set.contains("StrikeDirection")){
            str+="StrikeDirection,";
        }
        if(!set.contains("Strike")){
            str+="Strike,";
        }
        if(!set.contains("Direction")){
            str+="Direction,";
        }
        if(!set.contains("Clination")){
            str+="Clination,";
        }
        if(!set.contains("Length")){
            str+="Length,";
        }
        if(!set.contains("TopDepth")){
            str+="TopDepth,";
        }
        if(!set.contains("Width")){
            str+="Width,";
        }
        if(!set.contains("FractureBeltWidth")){
            str+="FractureBeltWidth,";
        }
        if(!set.contains("Feature")){
            str+="Feature,";
        }
        if(!set.contains("LatestActivePeriod")){
            str+="LatestActivePeriod,";
        }
        if(!set.contains("StartTimeEst")){
            str+="StartTimeEst,";
        }
        if(!set.contains("VDisplaceEst")){
            str+="VDisplaceEst,";
        }
        if(!set.contains("VDisplaceEr")){
            str+="VDisplaceEr,";
        }
        if(!set.contains("HDisplaceEst")){
            str+="HDisplaceEst,";
        }
        if(!set.contains("TDisplaceEst")){
            str+="TDisplaceEst,";
        }
        if(!set.contains("TDisplaceEr")){
            str+="TDisplaceEr,";
        }
        if(!set.contains("AveVRate")){
            str+="AveVRate,";
        }
        if(!set.contains("AveVRateEr")){
            str+="AveVRateEr,";
        }
        if(!set.contains("AveHRate")){
            str+="AveHRate,";
        }
        if(!set.contains("AveHRateEr")){
            str+="AveHRateEr,";
        }
        if(!set.contains("StartTimeNewest")){
            str+="StartTimeNewest,";
        }
        if(!set.contains("NewVRate")){
            str+="NewVRate,";
        }
        if(!set.contains("NewVRateEr")){
            str+="NewVRateEr,";
        }
        if(!set.contains("NewHRate")){
            str+="NewHRate,";
        }
        if(!set.contains("NewHRateEr")){
            str+="NewHRateEr,";
        }
        if(!set.contains("MaxVRate")){
            str+="MaxVRate,";
        }
        if(!set.contains("MaxVRateEr")){
            str+="MaxVRateEr,";
        }
        if(!set.contains("MaxHRate")){
            str+="MaxHRate,";
        }
        if(!set.contains("MaxHRateEr")){
            str+="MaxHRateEr,";
        }
        if(!set.contains("EQEventCount")){
            str+="EQEventCount,";
        }
        if(!set.contains("EQEventRIBottom")){
            str+="EQEventRIBottom,";
        }
        if(!set.contains("EQEventRITop")){
            str+="EQEventRITop,";
        }
        if(!set.contains("Method")){
            str+="Method,";
        }
        if(!set.contains("MaxRuptureLength")){
            str+="MaxRuptureLength,";
        }
        if(!set.contains("AverageRuptureLength")){
            str+="AverageRuptureLength,";
        }
        if(!set.contains("ElapseTimeForLatestEQ")){
            str+="ElapseTimeForLatestEQ,";
        }
        if(!set.contains("SlipDepthEst")){
            str+="SlipDepthEst,";
        }
        if(!set.contains("SlipDepthEr")){
            str+="SlipDepthEr,";
        }
        if(!set.contains("AverageSlipRateEst")){
            str+="AverageSlipRateEst,";
        }
        if(!set.contains("AverageSlipRateEr")){
            str+="AverageSlipRateEr,";
        }
        if(!set.contains("CreepRateEst")){
            str+="CreepRateEst,";
        }
        if(!set.contains("CreepRateEr")){
            str+="CreepRateEr,";
        }
        if(!set.contains("CoSeismicMaxSlipEst")){
            str+="CoSeismicMaxSlipEst,";
        }
        if(!set.contains("CoSeismicMaxSlipEr")){
            str+="CoSeismicMaxSlipEr,";
        }
        if(!set.contains("CoSeismicAverageSlipEst")){
            str+="CoSeismicAverageSlipEst,";
        }
        if(!set.contains("CoSeismicAverageSlipEr")){
            str+="CoSeismicAverageSlipEr,";
        }
        if(!set.contains("LatestCoSeismicSlipEst")){
            str+="LatestCoSeismicSlipEst,";
        }
        if(!set.contains("LatestCoSeismicSlipEr")){
            str+="LatestCoSeismicSlipEr,";
        }
        if(!set.contains("nsb1")){
            str+="nsb1,";
        }
        if(!set.contains("nsb2")){
            str+="nsb2,";
        }
        if(!set.contains("nsb3")){
            str+="nsb3,";
        }
        if(!set.contains("ShowCode")){
            str+="ShowCode,";
        }
        if(!set.contains("CommentInfo")){
            str+="CommentInfo,";
        }
        return str;
    }

    private String getStrBySourceStr(String source){
        if(StringUtils.isEmpty(source)){
            return "0";
        }
         return source;
    }

    List<Integer> featureids= new ArrayList<>();
    private void initFeatureIds(){
        featureids.clear();
        featureids.add(111100);
        featureids.add(111101);
        featureids.add(111104);
        featureids.add(111102);
        featureids.add(111103);
        featureids.add(111110);
        /*featureids.add(111115);
        featureids.add(111116);*/
        featureids.add(111111);
        /*featureids.add(111112);
        featureids.add(111113);*/
        featureids.add(111120);
        featureids.add(111121);
        /*featureids.add(111122);
        featureids.add(111123);
        featureids.add(111125);
        featureids.add(111126);
        featureids.add(111127);
        featureids.add(111200);
        featureids.add(111201);
        featureids.add(111202);
        featureids.add(111203);
        featureids.add(111210);
        featureids.add(111211);
        featureids.add(111212);
        featureids.add(111213);
        featureids.add(111220);
        featureids.add(111221);
        featureids.add(111222);
        featureids.add(111223);
        featureids.add(111300);
        featureids.add(111301);
        featureids.add(111302);
        featureids.add(111303);
        featureids.add(111310);
        featureids.add(111311);
        featureids.add(111312);
        featureids.add(111313);
        featureids.add(111320);
        featureids.add(111321);
        featureids.add(111322);
        featureids.add(111323);*/
    }

    List<Integer> lastnewids= new ArrayList<>();
    private void initNewIds(){
        lastnewids.clear();
        lastnewids.add(33320000);
       /* lastnewids.add(33320300);
        lastnewids.add(33320200);*/
        lastnewids.add(33310300);
        lastnewids.add(33310302);
        lastnewids.add(33310301);
        lastnewids.add(33310200);
        lastnewids.add(33310100);
        //lastnewids.add(33310000);
        lastnewids.add(33300000);
        lastnewids.add(33310120);
        lastnewids.add(-33300000);
        /*lastnewids.add(33220000);
        lastnewids.add(33210000);
        lastnewids.add(33130000);
        lastnewids.add(33120000);
        lastnewids.add(33110000);
        lastnewids.add(33200000);
        lastnewids.add(33100000);
        lastnewids.add(33000000);
        lastnewids.add(32300000);
        lastnewids.add(32200000);
        lastnewids.add(32100000);
        lastnewids.add(32000000);
        lastnewids.add(31600000);
        lastnewids.add(31500000);
        lastnewids.add(31400000);
        lastnewids.add(31300000);
        lastnewids.add(31200000);
        lastnewids.add(31100000);
        lastnewids.add(31000000);
        lastnewids.add(23300000);
        lastnewids.add(20000000);
        lastnewids.add(10000000);
        lastnewids.add(-31100000);*/
    }

    public void savehddcActivefaultServiceFromShpFiles(List<List<Object>> list, String provinceName, String cityName, String areaName,String savefilename) {
        if(list!=null&&list.size()>0){
            Integer count=this.hddcActivefaultRepository.getCountByArea(provinceName,cityName,areaName);
            if(count>0){
                throw new RuntimeException("当前区县已有断层数据，请先删除数据再进行导入。");
            }
            initFeatureIds();
            initNewIds();
            List<HddcActivefaultEntity> datas= new ArrayList<>();
            for(int i=0;i<list.size();i++){
                List<Object> obs=list.get(i);
                HddcActivefaultEntity data = new HddcActivefaultEntity();
                data.setArea(areaName);
                data.setProvince(provinceName);
                data.setCity(cityName);
                data.setExtends8(savefilename);
                data.setId(obs.get(1).toString());
                data.setScale(Integer.valueOf(getStrBySourceStr(obs.get(2).toString())));
                data.setFracturezonename(obs.get(3).toString());
                data.setName(obs.get(4).toString());
                data.setFaultsegmentname(obs.get(5).toString());
                data.setStrikedirection(Integer.valueOf(getStrBySourceStr(obs.get(6).toString())));
                data.setStrike(Integer.valueOf(getStrBySourceStr(obs.get(7).toString())));
                data.setDirection(Integer.valueOf(getStrBySourceStr(obs.get(8).toString())));
                data.setClination(Integer.valueOf(getStrBySourceStr(obs.get(9).toString())));
                data.setLength(Double.valueOf(getStrBySourceStr(obs.get(10).toString())));
                data.setTopdepth(obs.get(11).toString());
                data.setWidth(Double.valueOf(getStrBySourceStr(obs.get(12).toString())));
                data.setFracturebeltwidth(Double.valueOf(getStrBySourceStr(obs.get(13).toString())));
                Integer feature=Integer.valueOf(getStrBySourceStr(obs.get(14).toString()));
                if(!featureids.contains(feature)){
                    throw new RuntimeException("断层类型数据不正确。");
                }
                data.setFeature(feature);
                Integer lastid=Integer.valueOf(getStrBySourceStr(obs.get(15).toString()));
                if(!lastnewids.contains(lastid)){
                    throw new RuntimeException("活动时代数据不正确。");
                }
                data.setLatestactiveperiod(lastid);
                data.setStarttimeest(obs.get(16).toString());
                data.setVdisplaceest(Double.valueOf(getStrBySourceStr(obs.get(17).toString())));
                data.setVdisplaceer(Double.valueOf(getStrBySourceStr(obs.get(18).toString())));
                data.setHdisplaceest(Double.valueOf(getStrBySourceStr(obs.get(19).toString())));
                data.setHdisplaceer(Double.valueOf(getStrBySourceStr(obs.get(20).toString())));
                data.setTdisplaceest(Double.valueOf(getStrBySourceStr(obs.get(21).toString())));
                data.setTdisplaceer(Double.valueOf(getStrBySourceStr(obs.get(22).toString())));
                data.setAvevrate(Double.valueOf(getStrBySourceStr(obs.get(23).toString())));
                data.setAvevrateer(Double.valueOf(getStrBySourceStr(obs.get(24).toString())));
                data.setAvehrate(Double.valueOf(getStrBySourceStr(obs.get(25).toString())));
                data.setAvehrateer(Double.valueOf(getStrBySourceStr(obs.get(26).toString())));
                data.setStarttimeest(obs.get(27).toString());
                data.setNewvrate(Double.valueOf(getStrBySourceStr(obs.get(28).toString())));
                data.setNewvrateer(Double.valueOf(getStrBySourceStr(obs.get(29).toString())));
                data.setNewhrate(Double.valueOf(getStrBySourceStr(obs.get(30).toString())));
                data.setNewhrateer(Double.valueOf(getStrBySourceStr(obs.get(31).toString())));
                data.setMaxvrate(Double.valueOf(getStrBySourceStr(obs.get(32).toString())));
                data.setMaxvrateer(Double.valueOf(getStrBySourceStr(obs.get(33).toString())));
                data.setMaxhrate(Double.valueOf(getStrBySourceStr(obs.get(34).toString())));
                data.setMaxhrateer(Double.valueOf(getStrBySourceStr(obs.get(35).toString())));
                data.setEqeventcount(Integer.valueOf(getStrBySourceStr(obs.get(36).toString())));
                data.setEqeventribottom(Integer.valueOf(getStrBySourceStr(obs.get(37).toString())));
                data.setEqeventritop(Integer.valueOf(getStrBySourceStr(obs.get(38).toString())));
                data.setMethod(obs.get(39).toString());
                data.setMaxrupturelength(Integer.valueOf(getStrBySourceStr(obs.get(40).toString())));
                data.setAveragerupturelength(Integer.valueOf(getStrBySourceStr(obs.get(41).toString())));
                data.setElapsetimeforlatesteq(Integer.valueOf(getStrBySourceStr(obs.get(42).toString())));
                data.setSlipdepthest(Integer.valueOf(getStrBySourceStr(obs.get(43).toString())));
                data.setSlipdepther(Integer.valueOf(getStrBySourceStr(obs.get(44).toString())));
                data.setAveragesliprateest(Double.valueOf(getStrBySourceStr(obs.get(45).toString())));
                data.setAveragesliprateer(Double.valueOf(getStrBySourceStr(obs.get(46).toString())));
                data.setCreeprateest(Double.valueOf(getStrBySourceStr(obs.get(47).toString())));
                data.setCreeprateer(Double.valueOf(getStrBySourceStr(obs.get(48).toString())));
                data.setCoseismicmaxslipest(Double.valueOf(getStrBySourceStr(obs.get(49).toString())));
                data.setCoseismicmaxsliper(Double.valueOf(getStrBySourceStr(obs.get(50).toString())));
                data.setCoseismicaverageslipest(Double.valueOf(getStrBySourceStr(obs.get(51).toString())));
                data.setCoseismicaveragesliper(Double.valueOf(getStrBySourceStr(obs.get(52).toString())));
                data.setLatestcoseismicslipest(Double.valueOf(getStrBySourceStr(obs.get(53).toString())));
                data.setLatestcoseismicsliper(Double.valueOf(getStrBySourceStr(obs.get(54).toString())));
                data.setNsb1(obs.get(55).toString());
                data.setNsb2(Integer.valueOf(getStrBySourceStr(obs.get(56).toString())));
                data.setNsb3(Integer.valueOf(getStrBySourceStr(obs.get(57).toString())));
                data.setShowcode(Integer.valueOf(getStrBySourceStr(obs.get(58).toString())));
                data.setCommentInfo(obs.get(59).toString());
                String pstr=obs.get(0).toString();
                data.setExtends15(pstr);
                data.setExtends16("CGCS2000");
                /*String[] ss1=pstr.split("\\(");
                if(ss1.length>=2){
                    String[] ss2=ss1[ss1.length-1].split("\\)");
                    if(ss2.length<=2){
                        String spacedata=ss2[0].replace(",",";").replace("; ",";").replace(" ",",");
                        data.setExtends5(spacedata);
                    }
                }*/
                pstr = pstr.replace(")), ((", "#");
                pstr = pstr.replace("), (", "#");
                String[] ss1=pstr.split("\\(");
                if(ss1.length>=2){
                    String[] ss2=ss1[ss1.length-1].split("\\)");
                    if(ss2.length<=2){
                        String spacedata=ss2[0].replace(",",";").replace("; ",";").replace(" ",",");
                        data.setExtends5(spacedata);
                    }
                }
                datas.add(data);
            }
            //deleteByCreateUser(provinceName,cityName,areaName);
            saveHddcActivefaultList(datas);
        }
    }

/* public static Object getApi(){
        String param = null;
     RestTemplate restTemplate = new RestTemplate();
     String forObject = restTemplate.getForObject(url, String.class);
        return forObject;
    }

    public static void main(String[] args) {
        getApi();
    }*/

    public void deleteByCreateUser(String provinceName, String cityName, String areaName){
        String createID=PlatformSessionUtils.getUserId();
        List<HddcActivefaultEntity> hddcActivefaultList = this.hddcActivefaultRepository.queryHddcActivefaultsByCreateuser(createID,provinceName,cityName,areaName);
        if(!PlatformObjectUtils.isEmpty(hddcActivefaultList) && hddcActivefaultList.size() > 0) {
            hddcActivefaultRepository.deleteAll(hddcActivefaultList);
        }
    }

}
